package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.Result;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.pojo.TbItemCat;
import com.dongdongshop.pojo.TbTypeTemplate;
import com.dongdongshop.service.TbBrandService;
import com.dongdongshop.service.TbItemCatSerive;
import com.dongdongshop.service.TbTypeTemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("specification")
public class TbSpecificationController {
    @Reference
    private TbItemCatSerive tbItemCatSerive;
    @Reference
    private TbBrandService tbBrandService;
    @Reference
    private TbTypeTemplateService tbTypeTemplateService;

    @RequestMapping("goodsEdit")
    public String goodsEdit(Model model){
        Long parentId = 0L;
        List<TbItemCat> tbItemCatList = tbItemCatSerive.getTbItemCat(parentId);
        model.addAttribute("tbItemCatList",tbItemCatList);

        return "/admin/goods_edit";
    }

    @RequestMapping("getTbItemCat/{parentId}")
    @ResponseBody
    public Result showSpecification(@PathVariable("parentId")Long parentId){
        try {
            List<TbItemCat> tbItemCatList = tbItemCatSerive.getTbItemCat(parentId);
            return Result.response(ResultEnum.SUCCESS).setData(tbItemCatList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.response(ResultEnum.SUCCESS).setData(e);
        }
    }
    @RequestMapping("getBrand/{id}")
    @ResponseBody
    public Result getBrand(@PathVariable("id")Long id){
        TbTypeTemplate tbBrand = tbTypeTemplateService.getBrand(id);
        return Result.response(ResultEnum.SUCCESS).setData(tbBrand);
    }
    @RequestMapping("showTypeId/{parentId}")
    @ResponseBody
    public Result showTypeId(@PathVariable("parentId")Long parentId){
        TbItemCat tbItemCat = tbItemCatSerive.showTypeId(parentId);
        return Result.response(ResultEnum.SUCCESS).setData(tbItemCat);
    }




}
